import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginVue from "eslint-plugin-vue";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";

import { createRequire } from "module";
const require = createRequire(import.meta.url);
const autoImport = require("./.eslintrc-auto-import.json");

/** @type {import('eslint').Linter.Config[]} */
export default [
  { files: ["**/*.{js,mjs,cjs,ts,vue}"] }, // 检查的文件格式
  {
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node,
        ...autoImport.globals
      }
    }
  }, // 定义不同环境下全局变量
  pluginJs.configs.recommended, // js推荐规则
  ...tseslint.configs.recommended, // ts推荐规则
  ...pluginVue.configs["flat/essential"], // vue推荐规则
  {
    files: ["**/*.vue"],
    languageOptions: { parserOptions: { parser: tseslint.parser } }
  }, // vue文件中ts的使用规则
  {
    rules: {
      "no-console": "warn",
      "vue/multi-word-component-names": "off"
    }
  },
  {
    // 设置忽略的文件类型
    ignores: ["*.css", "*.jpg", "*.png", "*.jpeg", "*.d.ts", "*.gif"]
  },
  eslintPluginPrettierRecommended
];
